#!/bin/bash
# linux下交叉编译thrift(ingenic X2000)
# 需要依赖的库
# boost openssl zlib

sh_folder=$(dirname $(readlink -f $0))

CXX=mips-linux-gnu-g++
[ -n "$CROSS_COMPILER_PREFIX" ] && CXX=$CROSS_COMPILER_PREFIX/$CXX

[ ! $($CXX -dumpmachine) ] \
    && echo "not install compiler mips-linux-gnu-g++,install please" \
    && exit -1

[ -z "$CROSS_COMPILER_PREFIX" ] && _bin=$(dirname "$(which mips-linux-gnu-g++)") && CROSS_COMPILER_PREFIX=$(dirname "$_bin")

machine=$($CXX -dumpmachine)

# X2000工具链接没有提供zlib,所以要指定使用自己编译的zlib库

TOOLCHAIN_FILE=$sh_folder/cmake/mips-linux-gnu.toolchain.cmake \
PREFIX=$sh_folder/dist/thrift-$machine \
PROJECT_FOLDER=$sh_folder/build/thrift-$machine \
BOOST_ROOT=$sh_folder/dist/boost_1_62_0_$machine \
BUILD_TYPE=RELEASE \
ZLIB_ROOT=$sh_folder/dist/zlib-1.2.9_$machine \
ZLIB_LIBRRY=$sh_folder/dist/zlib-1.2.9_$machine/lib/libz.a \
WITH_OPENSSL=ON \
OPENSSL_ROOT_DIR=$sh_folder/dist/openssl-1.1.0d_$machine \
CROSS_COMPILER_PREFIX=$CROSS_COMPILER_PREFIX \
$sh_folder/build-thrift.sh 
